<!DOCTYPE html>
<html>
	<head>
		<title>门店利润查询</title>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">
		<%include("/common/include.html"){}%>
	</head>
	<link rel="stylesheet" href="${cxt!}/sb/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<style type="text/css">
		.textbox{
			padding-right:0px;
			background:url("${cxt !}/sb/themes/insdep/images/combo_arrow.png") no-repeat scroll right center transparent;
		} 
	</style>
	<script type="text/javascript">
		$(function() {
			var $form_div = $("#queryByCustom div");
			winResize($form_div);
			$(window).resize(function(){//当调整浏览器窗口的大小时，发生 resize 事件
				winResize($form_div);
			});
		})
		
		$(document).ready(function () {		
			queryCustomer()
			
		})
		/* 
			表格和表格拼接
		*/
		function queryCustomer(){
			$('#datagrid').datagrid({
				queryParams: {
					'minTime': $("#minTime").val(),
					'maxTime': $("#maxTime").val(),
					'selOrganIds': $("#organIdsEmployee").val(),
				},
				singleSelect: true,
				rownumbers: true, //显示序号
				url:'shopProfitQuery/queryPrice',
				collapsible: true,
				columns:[[
							{field:'project',title:'项目',width:100,align:'center'},
							{field:'chanplx',title:'产品类型',width:100,align:'center'},
							{field:'chanpmc',title:'产品名称',width:100,align:'center'},
							{field:'chanpsl',title:'数量',width:100,align:'center'},
							{field:'danj',title:'单价',width:100,align:'center'},
							{field:'shouruzj',title:'金额',width:100,align:'center'},
				]],
				onLoadSuccess:function(){
					var rows = $('#datagrid').datagrid('getRows');
					$(this).datagrid("autoMergeCells", ['project','chanplx']);
				}
			});
		};
		$.extend($.fn.datagrid.methods, {
		    autoMergeCells: function (jq, fields) {
		        return jq.each(function () {
		            var target = $('#datagrid');
		            if (!fields) {
		                fields = target.datagrid("project");
		            }
		            var rows = target.datagrid("getRows");
		            var i = 0,
		            j = 0,
		            temp = {};
		            for (i; i < rows.length; i++) {
		                var row = rows[i];
		                j = 0;
		                for (j; j < fields.length; j++){
		                    var field = fields[j];
		                    var tf = temp[field];
		                    if (!tf) {
		                        tf = temp[field] = {};
		                        tf[row[field]] = [i];
		                    } else {
		                        var tfv = tf[row[field]];
		                        if (tfv) {
		                            tfv.push(i);
		                        } else {
		                            tfv = tf[row[field]] = [i];
		                        }
		                    }                
		                }
		            }
		            $.each(temp, function (field, colunm) {
		                $.each(colunm, function () {
		                    var group = this;
		                    if (group.length > 1) {
		                        var before,
		                        after,
		                        megerIndex = group[0];
		                        for (var i = 0; i < group.length; i++) {
		                            before = group[i];
		                            after = group[i + 1];
		                            if (after && (after - before) == 1) {
		                                continue;
		                            }
		                            var rowspan = before - megerIndex + 1;
		                            if (rowspan > 1) {
		                                target.datagrid('mergeCells', {
		                                    index: megerIndex,
		                                    field: field,
		                                    rowspan: rowspan
		                                });
		                            }
		                            if (after && (after - before) != 1) {
		                                megerIndex = after;
		                            }
		                        }
		                    }
		                });
		            });
		        });
		    }
		});
		function customerInfo_xls(){
			var minTime = $("#minTime").val();
			var maxTime = $("#maxTime").val();
			var selOrganIds = $("#organIdsEmployee").val();
			var url = "${cxt!}/shopProfitQuery/excel?minTime="+minTime+"&maxTime="+maxTime+"&selOrganIds="+selOrganIds;
			window.location.href = url;
		}
	</script>
	<body class="easyui-layout">
		<div id="dianyuanmessage" class="easyui-window" title="店员" data-options="collapsible:false,minimizable:false,maximizable:false,closable:true,resizable:true" style="width:750px;height:400px;padding:5px;" data-options="cls:'theme-panel-orange'" closed="true">
			<table id="tablevisit"></table>
		</div>
			<div data-options="region:'north',split: true,title:'快速查询'" style="height:200px;padding:10px;">				
				<form id="queryByCustom"  method="post">
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">店面名称：</label>
						<input id="organEmployee" type="text" readonly style="width: 200px; height: 30px; padding-left: 10px;border-radius:3px" onclick="showMenuEmployee(); return false;" class="textbox" value="${curOrgan.name! }"/>
						<input name="selOrganIds" id="organIdsEmployee" type="hidden" value="${curOrgan.ids! }">
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">最早日期：</label>
						<input name="minTime" id="minTime" value='${date()}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center">
					</div>
					
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">最晚日期：</label>
						<input name="maxTime" id="maxTime" value='${date()}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center">
					</div>
					
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">搜索</label>
						<a href="#" onclick="queryCustomer()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="height:32px;width:212px;text-align:center">搜索</a>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='customerInfo_xls()' class="easyui-linkbutton" data-options="iconCls:'icon-pageexcel'" style="width:212px">导出</a>
					</div>
				</form>
			</div>
			<div data-options="region:'center'" style="overflow-x:hidden;">
				<table id="datagrid"></table>
			</div>
			<div id="menuContentEmployee" class="menuContentEmployee" style="display: none; position: absolute;z-index: 10;">
				<ul id="organSelectTreeEmployee" class="ztree" style="margin-top: 0;width: 200px;"></ul>
			</div>
	</body>
	<!-- 店员标签门店树形图 -->
		<script type="text/javascript">
			var organIdsEmployee=$('#organIdsEmployee').val();
			var settingEmployee = {
				async : {
					enable : true,
					url : '${cxt!}/common/getOrgenTree',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					otherParam : {
						"organIds" : organIdsEmployee
					},
					type : "post"
				},
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClickEmployee,
					onAsyncSuccess : organTreeOnAsyncSuccessEmployee
				}
			};
			var flagEmployee=0;//只初始化一次标识
			function organTreeOnAsyncSuccessEmployee(event, treeId, msg) {
				if(flagEmployee == 0){
					var organTree = $.fn.zTree.getZTreeObj("organSelectTreeEmployee");
					var nodes = organTree.getNodes();
					flagEmployee = 1;
				}
			}
			function onClickEmployee(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("organSelectTreeEmployee");
				var path = "";
				var sNodes = zTree.getSelectedNodes();
				if (sNodes.length > 0) {
					var node = sNodes[0].getPath();
					for(var i =0;i<node.length;i++){
						if(i == (node.length-1)){
							path += node[i].name;
						}else{
							path += node[i].name + "/";
						}
					}
				}
				var cityObj = $("#organEmployee");
				cityObj.attr("value", path);
				$("#organIdsEmployee").attr("value", treeNode.id);
				hideMenuEmployee();
			}
			function showMenuEmployee() {
				var cityObj = $("#organEmployee");
				var cityOffset = $("#organEmployee").offset();
				$("#menuContentEmployee").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
				$("body").bind("mousedown", onBodyDownEmployee);
			}
			function hideMenuEmployee() {
				$("#menuContentEmployee").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDownEmployee);
			}
			function onBodyDownEmployee(event) {
				if (!(event.target.id == "menuBtn" || event.target.id  == "menuContentEmployee" || $(event.target).parents("#menuContentEmployee").length > 0)){
					hideMenuEmployee();
				}
			}
			$.fn.zTree.init($("#organSelectTreeEmployee"), settingEmployee);
		</script>
</html>
